<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class MenuTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {   
        $table = $this->table('menu');
        $table->addColumn('type','boolean',array('limit' => 1, 'comment' => '菜单类型 1 系统菜单  2 店铺菜单'));
        $table->addColumn('parent_id','integer',array('limit' => MysqlAdapter::INT_REGULAR,'default' => 0, 'comment' => '所属父级分类'));
        $table->addColumn('sort','integer',array('limit' => MysqlAdapter::INT_REGULAR,'default' => 0, 'comment' => '排序'))->addIndex('sort');
        $table->addColumn('title','string',array('limit' => 30,'comment' => '菜单标题'));
        $table->addColumn('icon','string',array('limit' => 255,'default' => '','comment' => '菜单图标'));
        $table->addColumn('url','string',array('limit' => 100,'default' => '#','comment' => '菜单地址'));
        $table->addColumn('param','string',array('limit' => 100,'default' => '','comment' => '菜单参数'));
        $table->addColumn('node','string',array('limit' => 100,'default' => '','comment' => '权限节点'));
        $table->addColumn('display','boolean',array('limit' => 1, 'comment' => '是否左侧显示 0 否  1 是'));
        $table->addColumn('status','boolean',array('limit' => 1, 'comment' => '是否启用 0 否 1是','default' => 1));
        $table->addTimestamps('create_time','update_time');
        $table->create();
        $this->up();

    }


    public function up()
    {
        $rows = [
            [
              'type'    => 1,
              'parent_id'  => 0,
              'sort' => 0,
              'title' => '权限管理',
              'url' => '#',
              'display' => 1,
            ],
            [
                'type'    => 1,
                'parent_id'  => 1,
                'sort' => 0,
                'title' => '管理员列表',
                'url' => '/admin/admin',
                'node' => 'admin@admin@index',
                'display' => 1,
            ],
            [
                'type'    => 1,
                'parent_id'  => 1,
                'sort' => 0,
                'title' => '角色列表',
                'url' => '/admin/role',
                'node' => 'admin@role@index',
                'display' => 1,
            ],
            [
                'type'    => 1,
                'parent_id'  => 1,
                'sort' => 0,
                'title' => '菜单列表',
                'url' => '/admin/menu',
                'node' => 'admin@menu@index',
                'display' => 1,
            ],
            [
                'type'    => 1,
                'parent_id'  => 0,
                'sort' => 0,
                'title' => '店铺管理',
                'url' => '#',
                'node' => '',
                'display' => 1,
            ],
            [
                'type'    => 1,
                'parent_id'  => 2,
                'sort' => 0,
                'title' => '店铺列表',
                'url' => '/admin/store',
                'node' => 'admin@store@index',
                'display' => 1,
            ],
            [
                'type'    => 2,
                'parent_id'  => 0,
                'sort' => 0,
                'title' => '店铺列表',
                'url' => '/admin/store',
                'node' => 'admin@store@index',
                'display' => 1,
            ],
        ];

        $this->table('menu')->insert($rows)->save();
    }
}
